<template>
  <div class="index-head">
    <sticky :sticky-top="80">
      <div class="top-button">
        <div class="tip-wrap">
          <span class="left-tip">{{ assetsDate.status === 'up' ? '售卖中' : '已停售' }}</span>
        </div>
        <ul>
          <li>资产包名称:{{ assetsDate.name }}</li>
          <li>授课类型:{{ assetsDate.type | typeFilter }}</li>
          <li>课程:共{{ assetsDate.assetsNum }}个</li>
          <li>价格:共{{ assetsDate.price }}元</li>
          <li>销售:共{{ assetsDate.orderNum }}家</li>
        </ul>
        <div style="float:right;">
          <el-button v-if="assetsDate.status === 'up'" type="primary" @click="openClass">下架</el-button>
          <el-button v-if="assetsDate.status === 'down'" type="primary" @click="openClass">上架</el-button>
        </div>
      </div>
    </sticky>
  </div>
</template>

<script>
import Sticky from '@/components/Sticky'
import { updateAssets } from '@/api/subject/digitalAssets' // 数据接口
export default {
  components: {
    Sticky
  },
  filters: {
    typeFilter(type) {
      const typeMap = {
        live: '直播',
        record: '录播',
        tutorial: '面授',
        blend: '混合',
        other: '其他'
      }
      return typeMap[type]
    }
  },
  props: {
    assetsDate: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
    }
  },
  methods: {
    openClass() {
      if (this.assetsDate.status === 'up') {
        this.assetsDate.status = 'down'
      } else {
        this.assetsDate.status = 'up'
      }
      updateAssets(this.assetsDate).then(res => {
        this.$notify({
          title: '成功',
          message: '更新成功',
          type: 'success',
          duration: 2000
        })
      })
    }
  }
}
</script>

<style lang="scss">
.index-head {
  .top-button {
    width: 100%;
    height: 70px;
    line-height: 70px;
    padding: 0 20px;
    position: relative;
    background-color: #ebf4ff;
    min-width:1000px;
    ul {
      margin: 0;
      padding: 0;
      list-style: none;
      float: left;
      li {
        float: left;
        margin-right: 20px;
        color: #585858;
      }
    }
    .tip-wrap {
      height: 70px;
      line-height: 70px;
      text-align: center;
      float: left;
      width: 100px;
      margin-right: 20px;
      .left-tip {
        display: inline-block;
        width: 100%;
        height: 36px;
        line-height: 36px;
        text-align: center;
        border-radius: 4px;
        background-color: #1ebb90;
        color: #fff;
      }
    }
  }
}
</style>
